package com.voracious.ep1cG4m3.framework;

/*  
 *  Ep1c G4m3 -- A parody platformer
 * 
 *  Copyright (C) 2011  Voracious Softworks
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */


import javax.swing.JPanel;

import com.voracious.ep1cG4m3.utils.ScreenResultEvent;

/**
 * Absract super class all screens must extend.
 * 
 * @author Voracious Softworks
 * @see Drawable
 */

public abstract class Screen extends JPanel {
	/**
	 * Generated by eclipse
	 */
	private static final long serialVersionUID = 8843433126634456511L;
	
	int myId;
	ScreenResultEvent myListener;
	
	/**
	 * Sets id to be returned for identifying in the calling class and the class that will be returned to.
	 * 
	 * @param id unique screen id
	 * @param listener method that the screen will return a result to.
	 */
	
	public Screen(int id, ScreenResultEvent listener){
		myId = id;
		myListener = listener;
		setVisible(true);
		setOpaque(false);
	}
	
	/**
	 * Supplies the id that the screen should send to onActivityResult in Menu
	 * 
	 * @return this screen's id
	 */
	
	public int getId(){
		return myId;
	}
	
	/**
	 * The game object that called the screen. Needed to call onActivityResult.
	 * 
	 * @return the class that the screen will return a result to
	 */
	
	public ScreenResultEvent getListener(){
		return myListener;
	}
	
	/**
	 * Called when the screen is being switched to. Each screen can initialize GUI elements and listeners here.
	 */
	
	public abstract void start();
	
	/**
	 * Called when switching to another screen. Each screen MUST remove it's specific listeners here.
	 */
	
	public abstract void stop();
	
	/**
	 * A method to call when GUI elements are interacted with.
	 * 
	 * @param id id for the GUI element
	 * @param type Action type
	 */
	
	protected void dispatchResult(int type){
		myListener.onScreenResult(getId(), type);
	}
}
